home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / Developer Documentation / Recipes, Tech Notes & Articles / Tech Notes / Creating OpenDoc Objects next >
Encoding:
Text File  |  1996-02-05  |  2.6 KB  |  54 lines  |  [TEXT/ttxt]

  1. OpenDocâ„¢ Recipes
  2.  
  3. Creating OpenDoc objects
  4. By The OpenDoc Design Team
  5. Feb 2, 1996.
  6.  
  7.  
  8. © 1993-1996  Apple Computer, Inc. All Rights Reserved.
  9. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  10. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  11.  
  12.  
  13. Using Factory Methods
  14.  
  15. OpenDoc provides factory methods to create many OpenDoc objects (ODPart, ODDraft, ODWindow). The factory methods are associated with the factory objects. For example, the factory object of all persistent objects (ODPart, ODFrame, ODLink  etc) is ODDraft.
  16.  
  17. Clients of OpenDoc MUST use these factory methods to create the desired OpenDoc objects.
  18.  
  19. The main reason for using factory methods is for object distribution.  Factory object ensures objects are created in the desired process. It also ensures that an object is instantiated correctly before it is being returned for use by clients.
  20.  
  21.  
  22. Creating your own objects for OpenDoc
  23.  
  24. There are situations where a client of OpenDoc needs to create its own OpenDoc object (i.e., an object whose class is a subclass of ODObject and is defined by the client). Typically these objects are created by a shell plugin (ODDispatchModule, ODFocusModule and other ODObject subclasses).
  25.  
  26. For those cases, the client needs to use the OpenDoc utility call ODNewObject. The call can be found in ODNewObj.h and ODNewObj.cpp. (For more information on the method, please refer to the utility documentation.)
  27.  
  28. Sample Code
  29.  
  30. The following code fragment is taken from ScriptRunner shell plug-in sample code. What this shell plug-in does is creating an object to be installed in the namespace.
  31.  
  32. #ifndef _ODNEWOBJ_
  33. #include "ODNewObj.h"
  34. #endif
  35.     ...
  36.     objNameSpace = nameSpMgr->CreateNameSpace(ev,
  37.                         kOSAScriptingTool,
  38.                         kODNULL,
  39.                         (ODULong)1,
  40.                         kODNSDataTypeODObject);
  41.         
  42.     agent = (Sample_ScriptRunnerAgent*) ODNewObject("Sample::ScriptRunnerAgent");
  43.                 
  44.     ((ODObjectNameSpace*)objNameSpace)->Register(ev, kOSAScriptingTool, agent);
  45.     ...
  46.  
  47.  
  48. Details
  49.  
  50. OpenDoc supports library unloading. That means when there is no outstanding object for a certain OpenDoc part editor, the part editor library is going to be unloaded. When the part editor is unloaded, all its imported libraries whose only connections are to the part library are also unloaded.
  51.  
  52. Suppose class A and part class P are in the same code fragment and object a (of class A) is created by part p (of class P). When p is deleted and its library gets unloaded, object a will become invalid also because its library (which is the library for P) is unloaded.
  53.  
  54. ODNewObject has special code to prevent a library from being unloaded when the input object is still outstanding.